<% add_decidim_page_title(t(".title")) %>
<div class="card" id="committee_members">
  <div class="item_show__header">
    <h1 class="item_show__header-title">
      <%= t ".title" %>
    </h1>
  </div>

  <div class="card-section p-4">
    <div class="row column">
      <%= t ".invite_to_committee_help" %>
    </div>

    <div class="row column">
      <div data-committee_link>
        <%= decidim_initiatives.new_initiative_committee_request_url(current_initiative) %>
        <%= icon_link_to "clipboard-line", "#", t(".invite_to_committee_help"), class: "card--list__data__icon invite-users-link" %>
      </div>
    </div>
  </div>
</div>

<div class="table-stacked mt-4">
  <table class="table-list">
    <thead>
    <tr>
      <th><%= t "user", scope: "activemodel.attributes.initiatives_committee_member" %></th>
      <th><%= t "actions", scope: "decidim.admin.models.initiatives_committee_member.fields" %></th>
    </tr>
    </thead>
    <tbody>
      <% if current_initiative.committee_members.empty? %>
      <tr>
        <td><%= t ".no_members_yet" %></td>
        <td></td>
      </tr>
      <% end %>

      <% current_initiative.committee_members.each do |request| %>
        <tr data-id="<%= request.id %>">
          <td data-label="<%= t "user", scope: "activemodel.attributes.initiatives_committee_member" %>">
            <%= link_to request.user.name, "mailto:#{request.user.email}" %>
          </td>

          <td class="table-list__actions" data-label="<%= t "actions", scope: "decidim.admin.models.initiatives_committee_member.fields" %>">
            <button type="button" data-controller="dropdown" data-target="actions-initiative-committee-request-<%= request.id %>" aria-label="<%= t("decidim.admin.actions.actions_label", resource: request.user.name) %>">
              <%= icon "more-fill", class: "text-secondary" %>
            </button>

            <div class="inline-block relative">
              <ul id="actions-initiative-committee-request-<%= request.id %>" class="dropdown dropdown__action" aria-hidden="true">
                <% if allowed_to? :approve, :initiative_committee_member, request: request %>
                  <li class="dropdown__item">
                    <%= link_to approve_initiative_committee_request_path(current_initiative, request), class: "dropdown__button" do %> <%= icon "check-line" %>
                      <%= t(".approve") %>
                    <% end %>
                  </li>
                <% end %>

                <% if allowed_to? :revoke, :initiative_committee_member, request: request %>
                  <li class="dropdown__item">
                    <%= link_to revoke_initiative_committee_request_path(current_initiative, request), method: :delete, data: { confirm: t(".confirm_revoke") }, class: "dropdown__button" do %>
                      <%= icon "delete-bin-line" %>
                      <%= t(".revoke") %>
                    <% end %>
                  </li>
                <% end %>
              </ul>
            </div>
          </td>
        </tr>
      <% end %>
    </tbody>
  </table>
</div>

<%= append_stylesheet_pack_tag "decidim_initiatives_admin" %>
<%= append_javascript_pack_tag "decidim_initiatives_admin" %>
